package com.wsit.controller;

import com.wsit.pojo.PageBean;
import com.wsit.pojo.Result;
import com.wsit.pojo.Server;
import com.wsit.pojo.ServerPage;
import com.wsit.service.ServerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("/serve")
@Slf4j
@RestController
@RequestMapping("/serve")

public class ServerController {
    @Autowired
    private ServerService serverService;


    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询", notes = "分页查询", httpMethod = "GET")
    @GetMapping
    public Result Page(ServerPage serverPage) {
log.info("请求参数为",serverPage);
PageBean pageBean = serverService.page(serverPage);
return Result.success(pageBean);
    }

    /**
     * 添加
     * @param server
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Server", name = "server", value = "", required = true)
    })
    @ApiOperation(value = "添加", notes = "添加", httpMethod = "POST")
    @PostMapping
    public Result add(@RequestBody Server server){
        serverService.add(server);
        return Result.success();
    }

    /**
     * 根据id查询回显
     * @param id
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "根据id查询回显", notes = "根据id查询回显", httpMethod = "GET")
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Server server = serverService.getById(id);
        return Result.success(server);
    }
    /**
     * 修改信息
     * @param server
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Server", name = "server", value = "", required = true)
    })
    @ApiOperation(value = "修改信息", notes = "修改信息", httpMethod = "PUT")
    @PutMapping
    public Result update(@RequestBody Server server){
        serverService.update(server);
        return Result.success();
    }
    /**
     * 根据id删除
     * @param ids
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "List<Integer>", name = "ids", value = "", required = true)
    })
    @ApiOperation(value = "根据id删除", notes = "根据id删除", httpMethod = "DELETE")
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids) {
serverService.delete(ids);
        return Result.success();

    }

}
